package com.pubinfo.passbook.engine.process.variable.medicine;

import com.pubinfo.passbook.common.model.dto.witeoff.MedicineOnJobOrRetireDTO;
import com.pubinfo.passbook.common.model.ruler.PayInformation;
import com.pubinfo.passbook.common.service.ruler.InformationService;
import com.pubinfo.passbook.common.utils.ApplicationContextUilts;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 丙类自费总金额
 *
 * @author zhouch
 * @date 2022/3/8 14:24
 */
@Slf4j
public class BingAmountSelfProcessor extends MedicineVariableProcessor {

    InformationService informationService;


    public BingAmountSelfProcessor() {
        informationService = ApplicationContextUilts.getBean(InformationService.class);
    }

    @Override
    public String getName() {
        return "丙类自费总金额";
    }

    @Override
    public BigDecimal get(MedicineOnJobOrRetireDTO data) {

        log.info("执行参数处理器: {}", this.getClass().getSimpleName());

        List<PayInformation> payInformations = cache.getPayInformationData();

        BigDecimal sumAmountSelfs = new BigDecimal(0);

        Map<String, BigDecimal> types = new HashMap();
        types.put("丙", new BigDecimal("1"));
        for (PayInformation payInformation : payInformations) {

            BigDecimal sumAmountSelf = informationService.getSumAmountSelfByType(payInformation.getEInvoiceId(), types);
            if (sumAmountSelf.equals(new BigDecimal(-0.0000999))) {
                cache.markNeedAudit();
                log.info("{} ==> 需要人工审核.", getClass().getSimpleName());
                sumAmountSelf = BigDecimal.ZERO;
            }
            sumAmountSelfs = sumAmountSelfs.add(sumAmountSelf);
        }

        outputComputeMessage(sumAmountSelfs.toString());

        return sumAmountSelfs;
    }
}
